<?php
/*
Anmp组件
*/
class Com_anmp extends Acan{
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
	}
	//生成自身程序文件md5码缓存
	function up_set($mode='',$path='',$cachename='updates'){
		if($mode==3){$nrr = explode("\n",$this->up_list('',$path.'/'));}
		else{$nrr = explode("\n",$this->up_list());}
		if(empty($path)){$path = Acan_anmp_path;}
		$path = str_replace('\\','/',$path);
		foreach ($nrr as $key => $val) {
			if(empty($val)){continue;}
			$obj[$val] = md5(file_get_contents($path.'/'.$val));
		}
		$Aobj->version_c = Acan_anmp_version_c;
		$Aobj->version_s = Acan_anmp_version_s;
		$Aobj->uptime = Acan_anmp_uptime;
		$Aobj->files = $obj;
		if($mode==2){
			$uppath = Acan_anmp_sync_upfile;
			if(file_exists($uppath)){unlink($uppath);}
			file_put_contents($uppath,serialize($Aobj));
			echo '生成更新文件成功 <br>';
		}else{
			Afun_filecache_set($cachename,$Aobj,0,'./adata/up/');
		}
	}
	function up_dev($data){
		$uppath = Acan_anmp_sync_upfile;
		if(file_exists($uppath)){unlink($uppath);}
		file_put_contents($uppath,serialize($data));
		return true;
	}
	function md5_list($lists,$dirpath='',$cachename='sync_self'){
		if(empty($dirpath)){
			$dirpath = Acan_anmp_path.'/';
		}
		$lists = explode("\n",$lists);
		foreach ($lists as $key => $val) {
			if(!empty($val)){$arr[$val] = md5(file_get_contents($dirpath.$val));}
		}
		$Aobj->version_c = Acan_anmp_version_c;
		$Aobj->version_s = Acan_anmp_version_s;
		$Aobj->uptime = Acan_anmp_uptime;
		$Aobj->files = $arr;
		Afun_filecache_set($cachename,$Aobj,0,'./adata/up/');
		return $Aobj;
	}
	//生成自身程序文件列表
	function up_list($pname='',$dirpath=''){
		if(!empty($pname)){$pname = $pname.'/';}
		if(empty($dirpath)){
			$dirpath = Acan_anmp_path.'/';
		}
		$file_list=scandir($dirpath,$dirsort);
		foreach($file_list as $key => $val){
			if($val == ".." || $val=="."){continue;}
			if (is_dir($dirpath.$val)){
				$Astr .= $this->up_list($pname.$val,$dirpath.$val.'/');
			}
			if (is_file($dirpath.$val)){
				$Astr .= $pname.$val."\n";
			}
		}
		return $Astr;
	}
	function find_list($type,$dirpath=''){
		if(empty($dirpath)){
			$dirpath = Acan_anmp_path.'/';
		}
		$list = $this->sync_list($type);
		foreach ($list['file'] as $key => $val) {
			$files .= $val."\n";
		}
		foreach ($list['dir'] as $key => $val) {
			$files .= $this->up_list($val,$dirpath.$val.'/');
		}
		return $files;
	}
	function sync_list($type){
		$list = array(
			'acan'=>array(
				'dir'=>array(
					'acan/acan',
					'acan/adata/navs',
					'acan/atpl/public',
					'acan/atpl/error',
					'acan/com/public',
					'acan/css',
					'acan/images',
					'acan/js'
				),
				'file'=>array(
					'acan/acommon.php',
					'acan/index.html'
				)
			),
			'anmp'=>array(
				'dir'=>array(
					'acan/app/anmp',
					'acan/atpl/anmp'
				),
				'file'=>array(
					'acan/config/anmp.php',
					'acan/config/config_user.php',
					'acan/anmp.php',
				)
			),
			'asale'=>array(
				'dir'=>array(
					'acan/app/asale',
					'acan/atpl/asale'
				),
				'file'=>array(
					'acan/config/atable.php',
					'acan/asale.php',
				)
			)
		);
		if($list[$type]){return $list[$type];}else{return false;}
	}
	//需要屏蔽的内容
	function up_dis($type,$path,$files=''){
		$dis_dir = array(
			'lost+found',
			's',
			'config',
			'data',
			'server',
			'temp',
			'www',
			'run/cron',
			'acan/adata/logs',
			'acan/adata/up',
			'acan/app/asys',
			'acan/app/asale',
			'acan/atpl/asys',
			'acan/atpl/asale',
			'acan/js/app/asys',
			'acan/cmd',
			'acan/run',
			'acan/temp',
		);
		$dis_file = array(
			'acan/config/aconfig.php',
			'acan/config/aconfig.php.bak',
			'acan/config/atable.php',
			'acan/asys.php',
			'acan/asale.php',
			'acan/acmd.php',
			'acan/admin.php',
			'acan/center.php',
			'acan/domain.php',
			'acan/index.php',
		);
		$str_path = str_replace(realpath(Acan_anmp_path).'/','',realpath($path));
		if($type=='dir'){
			if(in_array($str_path,$dis_dir)){
				return false;
			}else{
				return true;
			}
		}
		if($type=='file'){
			if(in_array($str_path.'/'.$files,$dis_file)){
				return false;
			}else{
				return true;
			}
		}
		return;
	}
}

?>